//报数游戏
#include <bits/stdc++.h>

using namespace std;
int boy[1001];
int n, m;
int nxt(int k) {
  int b = 0;
  while (true) {
    while (boy[k] == 0)
      k = (k + 1) % n;
    b++;
    if (b == m)
      return k;
    k = (k + 1) % n;
  }
}

int main() {

  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    boy[i] = 1;
  }
  //	cout << nxt( 1) <<endl;

  int st = 0;
  int k = n;
  while (k > 1) {
    int kil = nxt(st);
    boy[kil] = 0;
    st = kil;
    k--;
  }
  for (int i = 0; i < n; i++) {
    if (boy[i] == 1) {
      cout << i + 1;
    }
  }
  return 0;
}
